package com.qianyu.project.web.controller.gs;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qianyu.project.entity.TenderBiddingHistory;
import com.qianyu.project.service.ITenderBiddingHistroyService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/2/3 10:30
 */
@RestController
@RequestMapping("/tenderBiddingHistorys")
public class TenderBiddingHistoryController {

    @Autowired
    private ITenderBiddingHistroyService tenderBiddingHistroyService;

    @PostMapping
    public Result save(@RequestBody TenderBiddingHistory tenderBiddingHistory) {
        tenderBiddingHistroyService.submit(tenderBiddingHistory);
        return ResultTool.success();
    }

    @GetMapping("/exist/{tenderId}")
    public Result isExist(@PathVariable String tenderId) {
        return ResultTool.success(tenderBiddingHistroyService.isExist(tenderId));
    }

    @PutMapping
    public Result update(@RequestBody TenderBiddingHistory tenderBiddingHistory) {
        tenderBiddingHistroyService.update(tenderBiddingHistory);
        return ResultTool.success();
    }

    @GetMapping("/page")
    public Result getPageList(@RequestParam Map<String, String> params) {
        return ResultTool.success(tenderBiddingHistroyService.getPageList(params));
    }

    @PutMapping("/operation")
    public Result cancel(@RequestBody TenderBiddingHistory tenderBiddingHistory) {
        tenderBiddingHistroyService.updateById(tenderBiddingHistory);
        return ResultTool.success();
    }

    @PutMapping("/open/{ids}")
    public Result batchOpen(@PathVariable String ids) {
        TenderBiddingHistory tenderBiddingHistory = new TenderBiddingHistory();
        tenderBiddingHistory.setStatus("2");
        tenderBiddingHistroyService.update(
                tenderBiddingHistory,
                new UpdateWrapper<TenderBiddingHistory>()
                .in("id", (Object[]) ids.split(","))
        );
        return ResultTool.success();
    }

    @PutMapping("/cooperation")
    public Result cooperation(@RequestBody TenderBiddingHistory tenderBiddingHistory) {
        tenderBiddingHistroyService.cooperation(tenderBiddingHistory);
        return ResultTool.success();
    }
}
